<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>UDD Home page</title>
</head>
<body>

	<h1>UDD Home</h1>
	
	<b>${infoMessage}</b>
	<br/>
	<br/>
	
	<a href="${pageContext.request.contextPath}/home/test-mail">Send email</a>
	<br/>
	<sec:authorize access="isAuthenticated()">
		Welcome, <sec:authentication property="principal.username"/>!
		<br>
		Roles:	<sec:authentication property="principal.authorities"/>
		<br>
		<a href="${pageContext.request.contextPath}/agents/view/<sec:authentication property="principal.username"/>">View profile</a>
		<br />
		<br />
		<form action="${pageContext.request.contextPath}/login/logout" method="POST">
      		<input type="submit" value="Log out" />
     		<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
    	</form>
	</sec:authorize>

	<sec:authorize access="isAnonymous()">
		<a href="${pageContext.request.contextPath}/login">Login</a>
		<br>
	</sec:authorize>
	
	<br>
	<a href="${pageContext.request.contextPath}/browse">Browse categories</a>
	<br>
	<a href="${pageContext.request.contextPath}/search">Search</a>
	<br>
	<a href="${pageContext.request.contextPath}/agents/register">Register agent. (Link is here for testing purposes, will be removed.)</a>
	
	<br>
	
	<sec:authorize ifAllGranted="${ adminRole }">
		<br>
		<a href="${pageContext.request.contextPath}/admins/view-all-agents">View all agents</a>
		<br>
		<a href="${pageContext.request.contextPath}/admins/view-all-advertisers">View all advertisers</a>
		<br>
		<a href="${pageContext.request.contextPath}/admins/view-all-inactive-advertisers">View all inactive advertisers</a>
		<br>
		<a href="${pageContext.request.contextPath}/agents/register">Register new agent</a>
		<br>
		<a href="${pageContext.request.contextPath}/advertisers/register">Register new advertiser</a>
	</sec:authorize>
		
	<br>
		<sec:authorize ifAnyGranted="${ advertiserRole }">
		<div>
			This part is visible only to role ${ advertiserRole }

			<table>
				<tr><td>&nbsp;</td></tr>
				<tr><td><a href="${pageContext.request.contextPath}/advertisers/edit">Edit advertiser profile</a></td></tr>
				<tr>
					<td><a href="${pageContext.request.contextPath}/advertisers/prepareUploadAdvert">Upload new advert</a></td>
					<td>&nbsp;&nbsp;&nbsp;</td>
					<td><a href="${pageContext.request.contextPath}/advertisers/prepareAdvert">My adverts</a></td>
				</tr>
			</table>
		</div>
		</sec:authorize>
		
	<br>
		<sec:authorize ifAnyGranted="${ agentRole }">
		<br>
		<a href="${pageContext.request.contextPath}/agents/settings">Settings</a>
		<br>
		<a href="${pageContext.request.contextPath}/agents/edit">Edit profile</a>
		<br>
		<a href="${pageContext.request.contextPath}/agents/upload-cv">Upload CV</a>
		</sec:authorize>
	<br>

</body>
</html>